package com.example.hydrogengenerator.model

import androidx.lifecycle.MutableLiveData
import com.example.hydrogengenerator.bean.CacheUtil
import com.example.hydrogengenerator.bean.SettingBean
import me.hgj.jetpackmvvm.base.viewmodel.BaseViewModel
import me.hgj.jetpackmvvm.callback.databind.BooleanObservableField
import me.hgj.jetpackmvvm.callback.databind.IntObservableField

class SettingModel : BaseViewModel() {
    val settingData = MutableLiveData(CacheUtil.getSettingBean())
    fun setModelSelect(model: Int) {
        val settingBean = settingData.value ?: return
        settingBean.model = model
        settingData.value = settingBean
    }

    fun setAutoOpen(open: Boolean) {
        val settingBean = settingData.value ?: return
        settingBean.autoOpen = open
        settingData.value = settingBean
    }

    fun addVolum() {
        val settingBean = settingData.value ?: return
        if (settingBean.volume == 15) return
        settingBean.volume += 1
        settingData.value = settingBean

    }

    fun miunsVolum() {
        val settingBean = settingData.value ?: return
        if (settingBean.volume == 0) return
        settingBean.volume -= 1
        settingData.value = settingBean
    }
    fun save() {
        CacheUtil.setSettingBean(settingData.value)
    }
}
